from skimage.restoration import estimate_sigma
import bm3d
import numpy as np

prepro_list = ['threshold','denoising']

def denoising(img):
    # img [0,255]
    sigma_est = estimate_sigma(img)
    img = bm3d.bm3d(img,sigma_est)
    img /= img.max()
    return img
    # img [0,1]

def threshold(img,thre=0.2):
    # img [0,1]
    img_thre = np.zeros(img.shape)
    img_thre[img>thre] = img[img>thre]
    return img_thre

def get_part(img,region):
    img_part = img[region[1]:region[3],region[0]:region[2]]
    return img_part

# 将截图得到的区域转换为原图像对应的大小
def translate(height,region):
    scale = height/1000
    region_new = []
    for ele in region:
        region_new.append(int(ele*scale))
    return region_new
